package com.demodis.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.demodis.dao.UserDaoI;
import com.demodis.dao.impl.UserDaoImpl;
import com.demodis.domain.TblUser;
import com.demodis.service.UserServiceI;
import com.demodis.util.Encrypt;
import com.demodis.util.Utils;

public class UserServiceImpl implements UserServiceI {

	UserDaoI userDao = new UserDaoImpl();

	@Override
	public TblUser doLogin(TblUser user) {
		user.setPassword(Encrypt.e(user.getPassword()));
		return userDao.getUser(user);
	}

	@Override
	public Object getUsers(TblUser user) {
		
		List<TblUser> list = userDao.getUsers(user);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", userDao.getUserNum(user));
		map.put("rows", list);
		return map;
	}

	@Override
	public boolean save(TblUser user) {
		user.setPassword(Encrypt.e(user.getPassword()));
		user.setRealNameAbbr(Utils.getChineseAbbr(user.getUserRealName()));
		return userDao.save(user);
	}

	@Override
	public boolean modify(TblUser user) {
		user.setRealNameAbbr(Utils.getChineseAbbr(user.getUserRealName()));
		return userDao.modify(user);
	}

	@Override
	public boolean delete(TblUser user) {
		return userDao.delete(user);
	}

	@Override
	public boolean modifyPass(TblUser user) {
		user.setPassword(Encrypt.e(user.getPassword()));
		return userDao.modifyPass(user);
	}

	@Override
	public Object getUsersCU(TblUser user) {
		List<TblUser> list = userDao.getUsersCU(user);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", userDao.getUserNumCUG(user));
		map.put("rows", list);
		return map;
	}

	@Override
	public boolean userExist(String username) {
		return userDao.userExist(username);
	}

}
